<?php

include "./mysql.php";

/*要查询某一篇文章的评论 根据article_id*/

$article_id = $_GET["article_id"];


$sql = "SELECT id,user_id,article_id,content as detail,created_time as postdate ,(SELECT nickname FROM t_users WHERE id= t_comments.user_id) as user ,(SELECT avatar FROM t_users WHERE id= t_comments.user_id) as user_avatar FROM t_comments WHERE article_id = {$article_id} ORDER BY id DESC";

$result = $mysqli->query($sql);

// 查询出的有可能有评论 还有可能没有评论
if ($result->num_rows) {
    while ($row = $result->fetch_assoc()) {
        $comments[] = $row;
    }
    $arr = array("code" => 200, "list" => $comments);
} else {
    $arr = array("code" => 404);
}

echo (json_encode($arr));
